package cool.taomu.toolkit.stock.controller.api

import com.google.gson.Gson
import cool.taomu.toolkit.stock.entity.StockData
import cool.taomu.toolkit.stock.service.PkService
import javax.inject.Inject
import javax.inject.Named
import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.Response
import org.slf4j.LoggerFactory

@Path("stock/api")
class StockCrawlerController {
    val static LOG = LoggerFactory.getLogger(StockCrawlerController);

    @Inject
    @Named("taomu.http.pathSpec")
    protected String pathSpec;

    @Inject
    @Named("taomu.title")
    protected String title

    @Inject
    PkService pk

    @GET
    @Path("/pk/{code}")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    def Response deviation(@PathParam("code") String code) {
        var pk = pk.getData(code).get() as String
        var res = new Gson().fromJson(pk,StockData)
        return Response.ok(res).build
    }
}
